package com.liangdemo.web.thread;


public class RunnableDemo2 implements Runnable {
    static Object ob = new Object();
    int sum = 1;

    public void run() {

        synchronized (ob) {

            // Thread.currentThread().setName("线程x");//设置线程的名字
            System.out.println(Thread.currentThread().getName() + " " + sum);
            System.out.println("线程优先级" + Thread.currentThread().getPriority());//查看线程优先级
            sum++;
        }

    }

    public static void main(String[] args) throws InterruptedException {
        RunnableDemo2 runnableDemo2 = new RunnableDemo2();
        Thread t2 = new Thread(runnableDemo2, "线程2");
        Thread t1 = new Thread(runnableDemo2, "线程1");
        t2.start();
        t1.start();
        t1.setPriority(1);//修改线程优先级
    }
}
